{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 单分支结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入取款金额：800\n",
      "取款成功，余额为： 200\n"
     ]
    }
   ],
   "source": [
    "money = 1000  # 余额\n",
    "s = int(input('请输入取款金额：'))  # 取款金额\n",
    "\n",
    "# 判断余额是否充足\n",
    "if s <= money :\n",
    "    money -= s\n",
    "    print('取款成功，余额为：', money)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. 双分支结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数：72\n",
      "72 是偶数\n"
     ]
    }
   ],
   "source": [
    "# 从键盘录入一个整数，编写程序让计算机判断奇偶性\n",
    "num = int(input('请输入一个整数：'))\n",
    "# 条件判断\n",
    "if num % 2 == 0:\n",
    "    print(num, '是偶数')\n",
    "else:\n",
    "    print(num, '是奇数')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. 多分支结构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个成绩：98\n",
      "A级\n"
     ]
    }
   ],
   "source": [
    "'''多分支结构，多选一执行\n",
    "从键盘录入一个整数 成绩\n",
    "90-100 A\n",
    "80-89 B\n",
    "70-79 C\n",
    "60-69 D\n",
    "0-59 E\n",
    "小于0或者大于100 为非法数据（不是有效范围）'''\n",
    "score = int(input('请输入一个成绩：'))\n",
    "# 判断\n",
    "if 90 <= score <= 100:\n",
    "    print('A级')\n",
    "elif 80 <= score <= 89:\n",
    "    print('B级')\n",
    "elif 70 <= score <= 79:\n",
    "    print('C级')\n",
    "elif 60 <= score <= 69:\n",
    "    print('D级')\n",
    "elif 0 <= score <= 59:\n",
    "    print('E级')\n",
    "else:\n",
    "    print('数据非法')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. 嵌套if使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是会员吗？y/n：y\n",
      "请输入您的购物金额：320\n",
      "是会员\n",
      "最终金额： 256.0\n"
     ]
    }
   ],
   "source": [
    "'''会员  >=200 8折\n",
    "        >100 9折\n",
    "        <100 不打折\n",
    "    非会员  >=200 95折\n",
    "           <200 不打折'''\n",
    "answer = input('你是会员吗？y/n：')\n",
    "money = float(input('请输入您的购物金额：'))\n",
    "\n",
    "# 外层判断是否是会员\n",
    "if answer == 'y':\n",
    "    print('是会员')\n",
    "    if money >= 200:\n",
    "        money *= 0.8\n",
    "        print('最终金额：', money)\n",
    "    elif 200 > money >= 100:\n",
    "        money *= 0.9\n",
    "        print('最终金额：', money)\n",
    "    else:\n",
    "        print('最终金额：', money)\n",
    "else:  # 非会员\n",
    "    print('不是会员')\n",
    "    if money >= 200:\n",
    "        money *= 0.95\n",
    "        print('最终金额：', money)\n",
    "    else:\n",
    "        print('最终金额', money)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.6.3",
   "language": "python",
   "name": "python3.6.3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
